<script setup lang="ts">
import { ref, onMounted } from "vue";
import { prodEvaluatePage } from "@/api/home";
import { CommentType } from "@/types/pages/commodity/detail";
import { useI18n } from "vue-i18n";

const { t } = useI18n();
const props = defineProps({
  evaluation: {
    type: Object,
    default: () => {},
  },
  id: {
    type: String,
    default: "",
  },
});

const commentParams = ref({
  current: 1,
  size: 5,
  prodId: props.id,
});
const commentList = ref<Array<IComment>>([]);
// 评论
const prodEvaluatePageFn = async () => {
  const { code, msg, data } = await prodEvaluatePage(commentParams.value);
  console.log(code, msg, data);
  if (code == 0) {
    commentList.value = data.records;
  } else {
    uni.$u.toast(msg);
  }
};
onMounted(() => {
  prodEvaluatePageFn();
});
</script>

<template>
  <view class="reviews" v-if="evaluation">
    <view class="top">
      <view class="left">
        <image
          style="width: 20px"
          mode="widthFix"
          src="@/static/image/reviews.png"
        ></image>
        <view class="num">
          {{ evaluation.avg }}
        </view>
        <span> ({{ evaluation.count }} {{ t("other.reviews") }}) </span>
      </view>
      <image
        style="width: 5.5px"
        mode="widthFix"
        src="@/static/image/right.png"
      ></image>
    </view>
    <view class="list">
      <view class="item" v-for="(item, index) in commentList" :key="index">
        <view class="top">
          <view class="left">
            <image v-if="item.userAvatar" :src="item.userAvatar"></image>
            <view class="">
              <view class="user-name">
                {{ item.userNickname }}
              </view>
              <view class="time">
                {{ item.createTime }}
              </view>
            </view>
          </view>
          <fui-rate
            :size="20"
            activeColor="#FF9900"
            :spacing="4"
            :score="item.score"
            :disabled="true"
          ></fui-rate>
        </view>
        <view class="desc">
          {{ item.content }}
        </view>
      </view>
    </view>
  </view>
</template>

<style lang="scss" scoped>
.reviews {
  .top {
    padding-top: 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;

    .left {
      display: flex;
      align-items: center;

      .num {
        margin: 0 10px;

        font-size: 18px;
        font-weight: bold;
        line-height: 20px;
        display: flex;
        align-items: center;
        letter-spacing: 0px;

        /* 外部/Black font */
        color: #303030;
      }

      span {
        font-size: 14px;
        font-weight: normal;
        line-height: 20px;
        display: flex;
        align-items: center;
        letter-spacing: 0px;

        /* 辅助文字 */
        color: #999999;
      }
    }
  }

  .list {
    display: flex;
    overflow-x: auto;
    padding: 20px 0;

    .item {
      min-width: 290px;
      border-radius: 8px;
      padding: 16px 12px;
      /* 外部/white */
      background: #ffffff;

      box-shadow: 0px -2px 50px 0px rgba(0, 0, 0, 0.05);
      margin-right: 20px;

      .top {
        display: flex;
        align-items: center;
        justify-content: space-between;

        .left {
          display: flex;
          align-items: center;

          image {
            width: 30px;
            height: 30px;
            border-radius: 50%;
            margin-right: 10px;
          }

          .user-name {
            font-size: 13px;
            font-weight: 600;
            line-height: 20px;
            display: flex;
            align-items: center;
            letter-spacing: 0px;

            font-feature-settings: "kern" on;
            color: #3d3d3d;
          }

          .time {
            margin-top: 5px;

            font-size: 10px;
            font-weight: normal;
            line-height: 10px;
            text-align: justify;
            /* 浏览器可能不支持 */
            letter-spacing: 0px;

            /* 辅助文字 */
            color: #999999;
          }
        }
      }

      .desc {
        margin-top: 10px;

        font-size: 13px;
        font-weight: normal;
        line-height: 18px;
        text-align: justify;
        /* 浏览器可能不支持 */
        letter-spacing: 0px;

        /* 外部/black 3 */
        color: #606060;
      }
    }

    .item:last-child {
      margin: 0;
    }
  }
}
</style>
